package com.leetcode.algorithm.y22.m06;

/**
 * 704. 二分查找
 * 
 * https://leetcode.cn/problems/binary-search/
 * 
 * @author jie.deng
 *
 */
class Question0704Solution01 {

	public int search(int[] nums, int target) {
		int low = 0;
		int high = nums.length - 1;
		while (low <= high) {
			int mid = low + ((high - low) >> 1);
			if (nums[mid] == target) {
				return mid;
			} else if (nums[mid] < target) {
				low = mid + 1;
			} else {
				high = mid - 1;
			}
		}
		return -1;
	}

}